#define _GNU_SOURCE
#include"head.h"
int fds[2];
int ret=0;
int transfile(int clientfd){
    printf"hellonihaoooooo：\n");
    pipe(fds);
    printf("transfile\n");
int fd=open("./file",O_RDWR);
ERROR_CHECK(fd,-1,"open");
train_t train;
memset(&train,0,sizeof(train));
train.dataLen=4;
strcpy(train.buf,"file");
struct stat stat;
memset(&stat,0,sizeof(stat));
fstat(fd,&stat);
send(clientfd,&train,4+strlen(train.buf),0);
memset(&train,0,sizeof(train));
train.dataLen=4;
*(int *)train.buf=stat.st_size;
send(clientfd,&train,4+train.dataLen,0);
int realsize=0;
while(1){
memset(&train,0,sizeof(train));
train.dataLen=read(fd,&train.buf,sizeof(train.buf));
int ret=send(clientfd,&train,4+train.dataLen,0);
if(train.dataLen==0){
break;
}
//对端断开，将不在发送跳出循环，再写的化，send会触发sigpipe信号,服务端的子进程会重复打印,client exitchild 14494 is leisure.
////
if(-1==ret){
break;
}
}
//char * transdata=(char *)mmap(NULL,stat.st_size,PROT_WRITE|PROT_READ,MAP_SHARED,fd,0);
//memset(transdata,0,stat.st_size);
//send(clientfd,transdata,stat.st_size,0);
//munmap(transdata,stat.st_size);
//close(fd)i
//while(realsize<stat.st_size){
//ret=splice(fd,0,fds[1],0,6000,SPLICE_F_MORE);
//if(-1==0){
//break;
//}
//splice(fds[0],0,clientfd,0,6000,SPLICE_F_MORE);
//realsize=ret+realsize;
//}
//close(fd);
//sendfile(clientfd,fd,NULL,stat.st_size);
return 0;
}
